<div class="content">
	<div class="tab_bar">
		<ul>
			<li class="tab_index" onclick="setTabContent(this);">编辑栏目</li>
		</ul>
		<button class="btn_tabbar" onclick="mySubmitForm(this);" return="channel/list.do">保 存</button>
	</div>


	<form id="myForm" action="channel/update.do" method="post" class="form-horizontal" onsubmit="return false;">

		<input type="hidden" name="id" value="${channel.id?c}"/>
        <input type="hidden" name="contentId" value="${channel.contentId?c}"/>
   		<input type="hidden" id="categoryIds" name="categoryIds" value="${channel.categoryIds!}"/>
	<div class="tab_content">
		<div class="tab_item tab_show">


			<div class="control-group">
				<label class="control-label">所属栏目：</label>
				<div class="controls">
					<select id="parentid" class="select_for_add"  name="pid">
						<option value="0"> -------- 顶级栏目 -------- </option>
						<#include "/common/channelSelect.html" />
						<@channelTree id = 0 node = -1/>
					</select>
					<div class="help-block">

					</div>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">栏目名称：</label>
				<div class="controls">
					<input class="input_for_add" id="name" name="name" type="text" value="${channel.name!}" />
					<div class="help-block"></div>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">语言引用：</label>
				<div class="controls">
					<input class="input_for_add" name="langkey" type="text" value="${channel.langkey!}" />
					<div class="help-block"></div>
				</div>
			</div>

			<div class="control-group">
				<label class="control-label">重定向地址：</label>
				<div class="controls">
					<input class="input_for_add" id="redirect" name="redirect" type="text" value="${channel.redirect!}"  />
					<div class="help-block"></div>
				</div>
			</div>

			<div class="control-group">
				<label class="control-label">栏目关键字：</label>
				<div class="controls">
					<input class="input_for_add" name="keywords" type="text" value="${channel.keywords!}"  />
					<div class="help-block"></div>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">栏目描述：</label>
				<div class="controls">
					<textarea class="textarea_for_add" name="description">${channel.description!}</textarea>
					<div class="help-block"></div>
				</div>
			</div>
			<div class="control-group">
				<label class="control-label">栏目图标：</label>
				<div class="controls">
					<input id="channelIcon" class="input_for_add" name="icon" type="text" value="${channel.icon!}" />

					<button onclick="uploadImage()">上传图片</button>
					<div class="help-block"></div>
				</div>
			</div>

			<div class="control-group">
				<label class="control-label">栏目模板：</label>
				<div class="controls">
					<select id="template" name="template">
						<#list templateList as tpl>
							<option value="${tpl}">${tpl}</option>
						</#list>
					</select>
					<div class="help-block"></div>
				</div>
			</div>

			<div class="control-group">
				<label class="control-label">栏目地址：</label>
				<div class="controls">
					<input class="input_for_add" name="url" type="text" value="${channel.url!}" />
					<div class="help-block">地址不能重复哦</div>
				</div>
			</div>

			<div class="control-group">
				<label class="control-label">栏目属性：</label>
				<div class="controls">
					<div>
						<select class="select_for_add" style="width: 60px;" name="hide">
							<#if channel.hide == true>
								<option value="1" selected="selected">显示</option>
								<option value="0">隐藏</option>
								<#else>
									<option value="1">显示</option>
									<option value="0" selected="selected">隐藏</option>
							</#if>
						</select>
						&nbsp; &nbsp;
						排序：<input class="input_for_add" name="sort" style="width:50px;" value="${channel.sort!}" type="text" />
						&nbsp; &nbsp;
						条数：<input class="input_for_add" name="rows" style="width:50px;" value="${channel.rows!}" type="text" />


					</div>
				</div>
			</div>

			<div class="control-group">
				<script type="text/plain" id="mushroomeditor" name="content"  style="height:350px;"></script>
				<textarea id="mrcmsContent" style="display:none">${channel.content!}</textarea>
			</div>

		</div>
	</div>
	</form>
</div>
<script type="text/javascript">
//设置栏目ID
var pid = '${channel.pid}';
$("#parentid").attr('value',pid);

$("#template").val("${channel.template!}");

var setting = {
    check: {
        enable: true,
        chkboxType :  { "Y" : "s", "N" : "ps" }
    },
    data: {
        simpleData: {
            enable: true
        }
    },
    callback: {
        onCheck: function(event,treeId, treeNode){

            var zTree = $.fn.zTree.getZTreeObj("tree"); //获取树
            var nodes = zTree.getNodes(); //获取每一个节点
            var nodeObjects = zTree.transformToArray(nodes);
            var selectData = [];
            for(var i=0; i <nodeObjects.length; i++){ //转换成数组
                var node = nodeObjects[i];
                console.log(node);
                if(node.checked){
                    selectData.push(node.id);
                }
            }
            $("#categoryIds").val(selectData.join(','));


        }
    }
};

var zNodes =[
];
//var categoryList = "${channel.categoryIds!}".split(",");
//$.ajax({
//    url:'category/all.do',
//    type:'get',
//    dataType:'json',
//    success:function(res){
//        $.each(res,function(index,o){
//            var node = {id:o.id,pId:o.pid,name:o.name};
//            for(var i=0; i <categoryList.length; i++) { //转换成数组
//                var nodeId = categoryList[i];
//                if (node.id == nodeId) {
//                    node.checked = true;
//                }
//            }
//            zNodes.push(node);
//        });
//        var tree = $.fn.zTree.init($("#tree"), setting, zNodes);
//        tree.expandAll(true);
//    }
//});

$(function(){
    $("input[name='type']").click(function(){
        editor.execCommand( 'source');
        if($(this).val() == 1){
            editor.setDisabled();
        }else{
            editor.setEnabled();
        }
        editor.setContent('');
    });



    if(window.editor != null){
        window.editor.destroy();
    }
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    window.editor = UE.getEditor('mushroomeditor');

    window.editor.ready(function(){
        $("#title").focus();//纠正显示
        editor.setContent($("#mrcmsContent").val());
    });
});

function mySubmitForm(obj){
    window.editor.sync();//手动提交需要手动同步编辑器数据
    submitActionForm(obj);
}




var _editor = UE.getEditor('upload_ue');
_editor.ready(function () {
    console.log("ueditor success!")
    //设置编辑器不可用
    _editor.setDisabled();
    //隐藏编辑器，因为不会用到这个编辑器实例，所以要隐藏
    _editor.hide();
    //侦听图片上传
    _editor.addListener('beforeInsertImage', function (t, arg) {
        console.log(arg);
    })
    //侦听文件上传
    _editor.addListener('afterUpfile', function (t, arg) {
        console.log(arg);
        $("#channelIcon").attr("value", arg[0].src);
    })
});

function uploadImage(){
    var myImage = _editor.getDialog("insertimage");
    myImage.open();
}
</script>